import {Component, Inject, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {UtilityService} from '../../../../../../service/utils.service';
import {appConfig} from '../../../../../../service/common';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {ActivatedRoute, Router} from '@angular/router';
import {DA_SERVICE_TOKEN, ITokenService} from '@delon/auth';
import {WorkitemModule} from '../../../../../../service/delivent/workItemModule';
import {ReuseTabService} from '@delon/abc';

@Component({
  selector: 'app-overview',
  templateUrl: './overview.component.html',
   styleUrls: ['./overview.component.less']
})
export class OverviewComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        public activatedRoute: ActivatedRoute,
        private nznot: NzNotificationService,
        @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,

    ) { }

    // 枚举值
    workGuid: string;

    // module
    workItem: WorkitemModule = new  WorkitemModule(); // 信息
   titlestr:string;
   SelectedIndex = 0;
    tabs = [

            {
            name   : '生命周期',
            router : 'workView/workLife',
            index : 0
        },
         {
            name   : '工作项详细',
            router : 'workView/detailed',
              index : 1
            },
            {
            name   : '标准清单',
             router : 'workView/standardlist',
               index :2

            },
            {
            name   : 'stash列表',
             router : 'workView/stashlist',
               index :3
            },
              {
            name   : '回退清单',
             router : 'workView/rollback',
               index :4
            },
            {
            name   : '撤销清单',
             router : 'workView/delaylist',
               index :5
            },
            {
            name   : '工作项明细',
             router : 'workView/workdetail',
               index :6
            },
            {
            name   : '投放计划',
             router : 'workView/delivery',
               index :7
            }

  ];
  id:string;
    ngOnInit() {
        this.activatedRoute.queryParams.subscribe(queryParams => {
            this.id = queryParams.workGuid;
        });
       if(this.id && this.id != undefined){
             localStorage.setItem('workGuid', this.id);
       }else{
           this.id = localStorage.getItem('workGuid');
       }
        this.workGuid = this.id
        this.token  = this.tokenService.get().seniortoken; // 绑定token
        this.getRouter(  {
            name   : '生命周期',
            router : 'workView/workLife',
            index : 0
        })
        this.getData()
}

    isCollapsed = false;
    widthLeft = 8;
    widthRight = 16;
    isShow = true;
    text='收起'
    token: any; // token
  toggleCollapsed(): void {
    this.isShow = !this.isShow;
    if(this.isShow === true){
        this.widthLeft = 8;
        this.widthRight = 16;
        this.text = '收起'
    }else{
         this.widthLeft = 2;
        this.widthRight = 22;
          this.text = '展开'
    }
  }
deliverdCount:number;
standardCount :number;
profiles:number;
branch:any;
isSpinning = false;
  getData(){
      this.isSpinning = true;
      let url='/sWorkitem/'+this.workGuid+'/general'
        this.utilityService.getData(appConfig.testUrl  + url)
            .subscribe(
                (val) => {
                    this.isSpinning = false;
                    this.workItem = val.result.workitem;
                    this.workItem.branch=val.result.branch.fullPath;
                    this.workItem.deliverdCount=val.result.deliverdCount;
                    this.workItem.standardCount = val.result.standardCount;
                    this.workItem.profiles = val.result.profiles;
                    this.workItem.lifecycle = val.result.lifecycle;

        },(error)=>{
               this.isSpinning = false;
                 this.nznot.create('error', error.code , error.msg);
        });
  }
getRouter(it){
  console.log(it)
      this.SelectedIndex = it.index;
      this.router.navigate([ this.tabs[it.index].router,this.workGuid]);
}
}
